package com.ssly.weixin.xichang.home.controller.api;

import com.ssly.weixin.xichang.common.domain.WeixinArticle;
import com.ssly.weixin.xichang.common.repository.WeixinArticleRepository;
import com.ssly.weixin.xichang.util.JsonResult;
import com.ssly.weixin.xichang.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/weixin-article")
public class WeixinArticleController {
    @Autowired
    private WeixinArticleRepository weixinArticleRepository;

    @GetMapping
    public Page<WeixinArticle> index(@RequestParam Integer pageIndex, @RequestParam Integer pageSize) {
        Pageable pageable = PageRequest.of(pageIndex, pageSize, Sort.Direction.DESC,"createTime");
        return weixinArticleRepository.findAll(pageable);
    }
    @GetMapping("/{id}")
    public JsonResult show(@PathVariable Integer id) {
        WeixinArticle weixinArticle = weixinArticleRepository.findById(id).get();
        return R.success("成功",weixinArticle);
    }

}
